class Exploitdb < Formula
  desc "Database of public exploits and corresponding vulnerable software"
  homepage "https://www.exploit-db.com/"
  url "https://github.com/offensive-security/exploitdb.git",
      tag:      "2021-12-15",
      revision: "90f7e494d694ceb9796c52f342e113998d5180fb"
  version "2021-12-15"
  license "GPL-2.0-or-later"
  head "https://github.com/offensive-security/exploitdb.git", branch: "master"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_monterey: "c80a24edfef52d8cf69ba1a7ea3dac6ed1b0b931188a48f1f2ffa48308429c29"
    sha256 cellar: :any_skip_relocation, arm64_big_sur:  "0a75089f9d054b2db90f29fd10af7fe7e1e30df9676b6e55f59df16d2c9ee53b"
    sha256 cellar: :any_skip_relocation, monterey:       "aed3a71fc441449526f56b042c8e060ab0caa620c34688206ad49a442c3048ac"
    sha256 cellar: :any_skip_relocation, big_sur:        "740fb2b9fcbbb197d21dad8f0bca3c87169fca0325eebec2bdaa44d61ba1c15c"
    sha256 cellar: :any_skip_relocation, catalina:       "e9904df17236fa2c06d38c6a752f9ecbd24fb7a20189e5fedd0a5ac883f49182"
    sha256 cellar: :any_skip_relocation, x86_64_linux:   "71d7302aff56f0e3fba098e998400f09b6ec6171283b77d0116cba616cdd010c"
  end

  def install
    inreplace "searchsploit",
              "rc_file=\"\"", "rc_file=\"#{etc}/searchsploit_rc\""

    optpath = opt_share/"exploitdb"
    inreplace ".searchsploit_rc" do |s|
      s.gsub! "\"/opt/exploitdb\"", optpath
      s.gsub! "\"/opt/exploitdb-papers\"", "#{optpath}-papers"
    end

    bin.install "searchsploit"
    etc.install ".searchsploit_rc" => "searchsploit_rc"

    pkgshare.install %w[.git exploits files_exploits.csv files_shellcodes.csv
                        shellcodes]
  end

  test do
    system "#{bin}/searchsploit", "sendpage"
  end
end
